<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<title>Marketing Kit - Mobile</title>
		<link rel="stylesheet" href="css/themes/Bootstrap.css">
		<link rel="stylesheet" href="css/jquery.mobile.structure-1.4.0.min.css" />
		<link rel="stylesheet" href="css/jquery.mobile.icons.min.css" />
		<script src="js/jquery-1.8.2.min.js"></script>
		<script src="js/jquery.mobile-1.4.0.min.js"></script>
		<script type="text/javascript" src="cordova.js"></script>
		
		<script>
			$(document).ready(function(){
				$("#btnLogin").click(function(){
					
					var username = $('#txtUsername').val();
					var password = $('#txtPassword').val();
					if(username=='' || password==''){
						alert("Username dan password harus diisi!");
						window.location='index.html';
					} else {
						$.mobile.loading( 'show', {
							text: 'Loading...',
							textVisible: true,
							theme: 'c',
							html: ""
						});
						var url = 'http://www.mamatzone.com/mkit/ws/loginws.php?user='+$('#txtUsername').val();
						//var url = 'http://10.0.2.2/mkit/ws/loginws.php?user='+$('#txtUsername').val();
						$.getJSON(url, function(data){
							try{
								if(password!=data.password){
									alert("Password Anda salah!");
									window.location='index.html';
								} else {
									//alert(data.username);
									window.localStorage.setItem('ls_username', data.username);
									window.localStorage.setItem('ls_compid', data.comp_id);
									window.localStorage.setItem('ls_compname', data.comp_name);
									window.localStorage.setItem('ls_lastversion', data.last_ver);
									window.localStorage.setItem('ls_update', 0);
									window.location='main_page.htm';
								}
							}catch(e){
								alert("User Anda belum terdaftar!");
								window.location='index.html';
							}
						});
					}
			  	});
			});
		</script>
	</head>
	<body>
		<div data-role="page" data-theme="c">
			<div data-role="header" data-position="inline" data-theme="c">
				<h1>Marketing Kit - Mobile</h1>
			</div>
			<div data-role="content" data-theme="c">
				<form action="#" method="get">
					<div data-role="fieldcontain">
						<label for="txtUsername">Username:</label>
						<input type="text" name="txtUsername" id="txtUsername" value=""  />
					</div>
					<div data-role="fieldcontain">
						<label for="txtPassword">Password:</label>
						<input type="password" name="txtPassword" id="txtPassword" value=""  />
					</div>
					<div data-role="fieldcontain" >
						<a data-role="button" name="btnLogin" id="btnLogin" data-theme="c" data-icon="user">Sign In</a>
					</div>
				</form>
			</div>
		</div>
	</body>
</html>